package com.qf.service.impl;

import com.qf.entity.Doctor;
import com.qf.entity.YuYue;
import com.qf.mapper.DoctorMapper;
import com.qf.pojo.BaseResult;
import com.qf.service.DoctorService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DoctorServiceImpl implements DoctorService {

    @Resource
    DoctorMapper doctorMapper;

    //登录
    @Override
    public BaseResult login(Doctor doctor) {
        BaseResult baseResult = new BaseResult();
        Doctor login = doctorMapper.login(doctor);
        //医生登录判断
        if(login!=null){
            if (login.getPassword().equals(doctor.getPassword())){
                baseResult.setCode(1);
                baseResult.setInfo("登录成功！");
                baseResult.setData(login);
                return baseResult;
            } else {
                baseResult.setCode(0);
                baseResult.setInfo("密码输入错误，请重新输入！");
                return baseResult;
            }
        }else{
            baseResult.setCode(0);
            baseResult.setInfo("用户不存在！");
            return baseResult;
        }
    }

    //查询医生个人权限
    @Override
    public BaseResult findByIdCard(Integer idCard) {
        BaseResult baseResult = new BaseResult();
        Doctor doctor = doctorMapper.findByIdCard(idCard);
        System.out.println(doctor+"8888888888888");
        baseResult.setData(doctor);
        return baseResult;
    }

    //展示医生个人信息
    @Override
    public BaseResult showInfoByIdCard(Integer idCard) {
        BaseResult baseResult = new BaseResult();
        Doctor doctor = doctorMapper.showInfoByIdCard(idCard);
        baseResult.setData(doctor);
        return baseResult;
    }

    //医生修改个人信息
    @Override
    public BaseResult changeInfoByIdCard(Doctor doctor) {
        BaseResult baseResult = new BaseResult();
        Integer integer = doctorMapper.changeInfoByIdCard(doctor);
        if(integer>0){
            baseResult.setCode(1);
            baseResult.setInfo("修改成功！");
            return baseResult;
        }else{
            baseResult.setCode(0);
            baseResult.setInfo("修改失败！");
            return baseResult;
        }

    }

 /*   @Override
    public BaseResult changeInfoByIdCard(Integer idCard) {
        return null;
    }*/

    //显示预约患者列表
    @Override
    public List<YuYue> findById(Integer id) {
        return doctorMapper.findById(id);
    }

    @Override
    public void updateByNum(String num) {
        doctorMapper.updateByNum(num);
    }
}






